package com.feng.annotation;

import java.lang.reflect.Method;

import org.aspectj.lang.annotation.Aspect;

@Aspect
@MyAnnotation1("this is annotation1")
public class AnnotationDemo implements Hello{
	@MyAnnotation2(description = "this is annotation2", isAnnotation = true)
	public void sayHello() {
		System.out.println("hello world!");
	}
	
	//Annotaion 测试
	public static void main(String args[]) throws ClassNotFoundException,
			SecurityException, NoSuchMethodException {
		Class<?> cls = Class.forName("com.feng.annotation.AnnotationDemo");
		boolean flag = cls.isAnnotationPresent(MyAnnotation1.class); if
		(flag) { System.out.println("判断类是annotation"); MyAnnotation1
		annotation1 = cls.getAnnotation(MyAnnotation1.class);
		System.out.println(annotation1.value()); }
		
		Method method = cls.getMethod("sayHello"); flag =
		method.isAnnotationPresent(MyAnnotation2.class); if (flag) {
		System.out.println("判断方法也是annotation"); MyAnnotation2 annotation2 =
		method .getAnnotation(MyAnnotation2.class);
		System.out.println(annotation2.description() + "\t" +
		annotation2.isAnnotation()); }
	}
}
